//
//  ViewController.m
//  相册
//
//  Created by dllo on 16/6/14.
//  Copyright © 2016年 zuzhiming. All rights reserved.
//

#import "ViewController.h"
#import "SecondViewController.h"
@interface ViewController ()

@property (nonatomic, retain) UIImageView *photoImageView;

@property (nonatomic, assign) NSInteger index;

@property (nonatomic, retain) NSMutableArray *dataArray;

@end

@implementation ViewController

- (void)dealloc
{
    [_photoImageView release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"相册";
    
    [self dataHandle];
    //加载封面
    [self createSubViews];
    
}

- (void)dataHandle
{
    self.dataArray = [NSMutableArray array];
    for (NSInteger i = 1; i <= 6; i++) {
        NSString *path = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%ld", i] ofType:@"jpg"];
        UIImage *image = [UIImage imageWithContentsOfFile:path];
        [self.dataArray addObject:image];
    }
    
    

}

//创建封面
- (void)createSubViews
{
    
    NSInteger num = 1;
    for (NSInteger i = 0; i < 3; i++) {
        for (NSInteger j = 0; j < 2; j++) {
            
            self.photoImageView = [[UIImageView alloc] initWithImage:self.dataArray[num - 1]];
            self.photoImageView.frame = CGRectMake(j * 180 + 25, 60 + i * 200 + 20, (self.view.bounds.size.width - 90) / 2, (self.view.bounds.size.height - 200) / 3);
            self.photoImageView.userInteractionEnabled = YES;
            
            self.photoImageView.tag = 1000 + num++;
            //点击
            UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
            [self.photoImageView addGestureRecognizer:tapGesture];
            [tapGesture release];
            
//            NSLog(@"%ld", self.photoImageView.tag);
            
            [self.view addSubview:_photoImageView];
            [_photoImageView release];
            
        }
    }
}

- (void)tapAction:(UITapGestureRecognizer *)tapGesture
{
    
        SecondViewController *svc = [[SecondViewController alloc] init];
        svc.imageArray = self.dataArray;
        //不知道啥意思
        svc.number = tapGesture.view.tag - 1000;
        
        [self.navigationController pushViewController:svc animated:YES];
        
        [svc release];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
